<?php

namespace App\Http\Controllers\App;

use App\Http\Controllers\Controller;
use App\Models\Image;
use App\Models\Setting;
use Illuminate\Http\Request;

class HomeController extends Controller
{
    /**
     * 获取轮播图
     * @param Request $request
     * @return array
     */
    public function swipe(Request $request)
    {
        $setting = Setting::where('code', 'swipe')->first();
        if (empty($setting)) {
            return jsonResponse(500);
        }
        $items = explode(config('common.delimiter'), $setting['value']);
        $images = [];
        foreach ($items as $item) {
            $image = Image::find($item);
            $images[] = $image;
        }
        return jsonResponse(config('common.successCode'), $images);
    }
}
